package javase.javase01.exercise05;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author: Gan
 * @date 2021/4/16 0016 20:26
 * @description:
 * 4.有这样的一个words数组，数组中每个字符串的格式为“词性:单词”
 * String[] words = {"verb:eat","verb:drink","verb:sleep",
 * "verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};
 * 根据单词性质动词verb全部存入verb.txt文件中
 * 根据单词性质名词noun全部存入noun.txt文件中
 **/
public class SolutionDemo {
    public static void main(String[] args) throws IOException {
        new File(".\\verb.txt").createNewFile();
        new File(".\\noun.txt").createNewFile();
        String[] words = {"verb:eat","verb:drink","verb:sleep",
                 "verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};
        FileOutputStream out1 = new FileOutputStream(".\\verb.txt");
        FileOutputStream out2 = new FileOutputStream(".\\noun.txt");
        for (String word: words) {
            if (word.startsWith("noun")){
                out2.write(word.getBytes());
                System.out.print(" ");
            }else out1.write(word.getBytes());
        }
        out1.close();
        out2.close();
    }
}
